import java.util.Stack;

public class Test {
    public static void main(String[] args) {
        MyStackUseQueue myStackUseQueue = new MyStackUseQueue();
        myStackUseQueue.push(1);
        myStackUseQueue.push(2);
        myStackUseQueue.push(3);
        myStackUseQueue.push(4);
        myStackUseQueue.push(5);
        int x = myStackUseQueue.pop();
        System.out.println(x);
        int y = myStackUseQueue.top();
        System.out.println(y);
    }
    //关于栈的逆波兰表达式求值问题的解答
    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (String str:tokens) {
            if (!isOperator(str)){
                int x = Integer.parseInt(str);
                stack.push(x);
            }else {
                int val2 = stack.pop();
                int val1 = stack.pop();
                switch (str){
                    case "+":
                        stack.push(val1 + val2);
                        break;
                    case "-" :
                        stack.push(val1-val2);
                        break;
                    case "*" :
                        stack.push(val1*val2);
                        break;
                    case "/" :
                        stack.push(val1/val2);
                        break;
                }
            }
        }return stack.pop();
    }
    public static boolean isOperator(String ch){
        if(ch.equals("+") || ch.equals("-")
                || ch.equals("*") || ch.equals("/")) {
            return true;
        }
        return false;
    }

    //关于栈的弹出压入序列问题的解答
    public static boolean IsPopOrder (int[] pushV, int[] popV) {
        if (pushV.length != popV.length){
            return false;
        }
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while (!stack.isEmpty() && j < popV.length && stack.peek() == popV[j]){
                stack.pop();
                j++;
            }
        }return stack.isEmpty();
    }
    //关于栈的括号匹配问题的解答：
    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '{' || ch == '['){
                stack.push(ch);
            }else {
                if(stack.isEmpty()){
                    return false;
                }
                char ch2 = stack.peek();
                if ((ch == ')' && ch2 == '(') || (ch == '}' && ch2 == '{') || (ch == ']' && ch2 == '[')){
                    stack.pop();
                }else {
                    return false;
                }
            }
        }if(stack.isEmpty()){
            return true;
        }return false;
    }
}
